#include "stdafx.h"
#include "BigInt.h"

using namespace System;
using namespace System::Text;
using namespace System::Collections::Generic;
using namespace Microsoft::VisualStudio::TestTools::UnitTesting;
using namespace APIAL;

namespace BigIntUnitTest
{
	[TestClass]
	public ref class ConversionUnitTest
	{
	private:
		TestContext^ testContextInstance;

	public: 
		/// <summary>
		///Gets or sets the test context which provides
		///information about and functionality for the current test run.
		///</summary>
		property Microsoft::VisualStudio::TestTools::UnitTesting::TestContext^ TestContext
		{
			Microsoft::VisualStudio::TestTools::UnitTesting::TestContext^ get()
			{
				return testContextInstance;
			}
			System::Void set(Microsoft::VisualStudio::TestTools::UnitTesting::TestContext^ value)
			{
				testContextInstance = value;
			}
		};

		#pragma region Additional test attributes
		//
		//You can use the following additional attributes as you write your tests:
		//
		//Use ClassInitialize to run code before running the first test in the class
		//[ClassInitialize()]
		//static void MyClassInitialize(TestContext^ testContext) {};
		//
		//Use ClassCleanup to run code after all tests in a class have run
		//[ClassCleanup()]
		//static void MyClassCleanup() {};
		//
		//Use TestInitialize to run code before running each test
		//[TestInitialize()]
		//void MyTestInitialize() {};
		//
		//Use TestCleanup to run code after each test has run
		//[TestCleanup()]
		//void MyTestCleanup() {};
		//
		#pragma endregion 

		[TestMethod]
		void TestBigIntTestingConstructor()
		{
			BigInt b1 = BigInt(10, 8);
			Assert::AreEqual<int>(10, b1.capacity);
			Assert::AreEqual<int>(1, b1.carryBits);
			Assert::AreEqual<int>(7, b1.nonCarryBits);
			Assert::AreEqual<BigInt::chunkType>(0x7F, b1.nonCarryBitsMask);
			Assert::AreEqual<BigInt::chunkType>(~0x7F, b1.carryBitsMask);
		};

		[TestMethod]
		void TestParseHexadecimalAgainstBinary()
		{
			BigInt b1 = BigInt(30, 8);
			BigInt b2 = BigInt(30, 8);
			b1.ParseHexadecimalString("123456789ABCDEF", true);
			b2.ParseBinaryString("100100011010001010110011110001001101010111100110111101111", true);
			Assert::AreEqual<int>(b2.size, b1.size);
			for (int i = 0; i < b2.size; i++) {
				Assert::AreEqual<BigInt::chunkType>(b2.chunks[i], b1.chunks[i]);
			}

			b1.ParseHexadecimalString("FEDCBA987654321", true);
			b2.ParseBinaryString("111111101101110010111010100110000111011001010100001100100001", true);
			Assert::AreEqual<int>(b2.size, b1.size);
			for (int i = 0; i < b2.size; i++) {
				Assert::AreEqual<BigInt::chunkType>(b2.chunks[i], b1.chunks[i]);
			}
		};

		[TestMethod]
		void TestParseHexadecimalRandom() {
			BigInt b1 = BigInt(30, 8);
			for (int i = 0; i < b1.capacity; i++) {
				b1.chunks[i] = ~b1.chunks[i];
			}
			b1.ParseHexadecimalString("1CEF", true);
			Assert::AreEqual<BigInt::chunkType>(0x6F, b1.chunks[0]);
			Assert::AreEqual<BigInt::chunkType>(0x39, b1.chunks[1]);
			Assert::AreEqual<int>(2, b1.size);
		}

	};
}
